<?php

namespace app\model\user;

use app\base\BaseModel;

/**
 * 模型-UserDebtLogModel
 * Class UserDebtLogModel
 * @package app\model
 */
class UserDebtLogModel extends BaseModel
{
    protected $name = 'user_debt_log';

    /**
     * 添加支付日志
     * @param $log
     * @param string $change
     * @return bool
     */
    public static function addLog($log, $change = 'pay')
    {
        $in_data = [
            'user_id' => $log['user_id'],
            'type' => $change,
            'last_price' => $log['last_price'],
            'price' => $log['price'],
            'detail' => $log['detail'],
            'add_date' => date("Y-m-d H:i:s"),
            'add_time' => time()
        ];
        $ret = self::insert($in_data);
        if ($ret !== false) {
            return true;
        }
        return false;
    }

    /**
     * 获取用余额变动信息
     * @param $map
     * @return array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getBalanceLog($map)
    {
        $log = self::where($map)->select();
        if (!empty($log)) {
            return $log;
        }
        return [];
    }
}